<?php

	include "kernel.php";

	$nav = $_SERVER["REQUEST_URI"];

	$nav = explode("/",$nav);

    $navc = count($nav);

    $nav = $nav[$navc-1];

	$img = $nav;


    $nav = explode("_",$nav);


    $army = $nav[0];


    if ($army == "r") $army = 1;
    elseif ($army == "b") $army = 2;

    $num = $nav[1];

    $num = ereg_replace("\.jpg$","",$num);


    if (ereg("m$",$num)) {
        $num = ereg_replace("m$","",$num);
    	$big = 1;
    }


    // check if there is such an award
    $r = mysql_query("select id from finalpilots where award".$num."=1 and army=$army");

    // if it is
    if (mysql_num_rows($r)>0) {

    	// if it is big
        if ($big) {

        	$f = fopen("img/awards/medals/$img","r");
            $fcont = fread($f,filesize("img/awards/medals/$img"));

        }
		else {

        	$f = fopen("img/awards/$img","r");
            $fcont = fread($f,filesize("img/awards/$img"));

        }


    }
    else {

    		mysql_query("insert into badguys (ip,date) values ('".$_SERVER[REMOTE_ADDR]."','".date("Y-m-d H:i:s")."')");

        	$f = fopen("img/awards/cr.jpg","r");
            $fcont = fread($f,filesize("img/awards/cr.jpg"));

    }


        echo $fcont;

?>